<template>
  <transition name="slide" appear>
    <div class="singer-detail">
      <music-list :songs="songs" :bg-image="bgImage" :title="title"></music-list>
    </div>
  </transition>
</template>

<script>
import { mapGetters } from "vuex";
import { getSingerMusic, getSimiSinger } from "@/request/api";
import { createSong } from "@/common/song";
import MusicList from "@/components/music-list/music-list";
export default {
  data() {
    return {
      artistInfo: {},
      songs: []
    };
  },
  components: {
    MusicList
  },
  computed: {
    ...mapGetters(["singer"]),
    title() {
      return this.singer.name;
    },
    bgImage() {
      return this.singer.avatar;
    }
  },
  created() {
    // console.log(this.singer);
    this.getDetail();
  },
  methods: {
    async getDetail() {
      if (!this.singer.id) {
        this.$router.push("/singer");
        return;
      }
      const { artist, hotSongs } = await getSingerMusic(this.singer.id);
      // 歌手信息
      this.artistInfo = artist;
      // const res = await getSimiSinger(this.singer.id);
      // console.log(this.artistInfo);

      // 热门歌曲
      this.songs = this._normalizeSongs(hotSongs);
    },
    _normalizeSongs(list) {
      let ret = [];
      list.forEach(item => {
        if (item.id && item.al.id) {
          ret.push(createSong(item));
        }
      });
      return ret;
    }
  }
};
</script>

<style lang="less" scoped>
.singer-detail {
  position: fixed;
  z-index: 77;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: @color-background;
}
.slide-enter-active,
.slide-leave-active {
  transition: all 0.3s;
}
.slide-enter,
.slide-leave-to {
  transform: translate3d(100%, 0, 0);
}
</style>